package com.alogic.html.util;

import java.util.Map;

import org.w3c.dom.Element;

import com.alogic.load.Loadable;
import com.anysoft.util.Configurable;
import com.anysoft.util.JsonTools;
import com.anysoft.util.Properties;
import com.anysoft.util.PropertiesConstants;
import com.anysoft.util.XMLConfigurable;
import com.anysoft.util.XmlElementProperties;
import com.anysoft.util.XmlTools;

/**
 * HtmlTag定义
 * @author duanyy
 * @since 1.6.12.27 [20190327 duanyy]
 * 
 * @version 1.6.12.36 [20190611 duanyy] <br>
 * - 重构html文档框架<br>
 */

public class HtmlTag extends Loadable.Abstract implements Configurable,XMLConfigurable{
	protected String id = "0";
	protected String[] attrs = null;
	protected String content = "__html";
	protected boolean inline = true;
	
	public HtmlTag(){
		
	}
	
	@Override
	public String getId() {
		return id;
	}
	
	public String[] getAttrs(){
		return attrs;
	}
	
	public String getContentId(){
		return content;
	}
	
	public boolean inline(){
		return inline;
	}

	@Override
	public void report(Element xml) {
		if (xml != null){
			XmlTools.setString(xml, "id", getId());
			XmlTools.setString(xml, "content", content);
			if (attrs != null){
				XmlTools.setString(xml, "attrs", attrs.toString());
			}
		}
	}

	@Override
	public void report(Map<String, Object> json) {
		if (json != null){
			JsonTools.setString(json, "id", getId());
			JsonTools.setString(json, "content", content);
			if (attrs != null){
				JsonTools.setString(json, "attrs", attrs.toString());
			}
		}
	}

	@Override
	public void configure(Properties p) {
		id = PropertiesConstants.getString(p,"id", "",true);
		attrs = PropertiesConstants.getString(p,"attr", "",true).split(",");
		content = PropertiesConstants.getString(p,"content", content,true);
		inline = PropertiesConstants.getBoolean(p,"inline", inline,true);
	}

	@Override
	public void configure(Element e, Properties p) {
		XmlElementProperties props = new XmlElementProperties(e,p);
		configure(props);
	}

}
